Completed
Push — master ( 17669b...b8e030 )
by Rain
02:40
created

Utils.js ➔ ... ➔ ???   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 1
rs 10
1
2
import window from 'window';
3
import $ from '$';
4
import _ from '_';
5
import ko from 'ko';
6
import {$win, $div, dropdownVisibility, data as GlobalsData} from 'Common/Globals';
0 ignored issues
show
Unused Code introduced by
The variable $div seems to be never used. Consider removing it.
Loading history...
7
import {ComposeType, EventKeyCode, SaveSettingsStep, FolderType} from 'Common/Enums';
8
import {Mime} from 'Common/Mime';
9
import {jassl} from 'Common/Jassl';
10
11
import Autolinker from 'Autolinker';
12
13
const trim = $.trim;
14
const inArray = $.inArray;
15
const isArray = _.isArray;
16
const isObject = _.isObject;
17
const isFunc = _.isFunction;
18
const isUnd = _.isUndefined;
19
const isNull = _.isNull;
20
const has = _.has;
21
const bind = _.bind;
22
const noop = () => {}; // eslint-disable-line no-empty-function
23
const noopTrue = () => true;
24
const noopFalse = () => false;
25
26
export {trim, inArray, isArray, isObject, isFunc, isUnd, isNull, has, bind, noop, noopTrue, noopFalse, jassl};
27
28
/**
29
 * @param {Function} func
30
 */
31
export function silentTryCatch(func)
0 ignored issues
show
Unused Code introduced by
The parameter func is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
32
{
33
	try {
34
		func();
35
	}
36
	catch (e) {} // eslint-disable-line no-empty
37
}
38
39
/**
40
 * @param {*} value
41
 * @returns {boolean}
42
 */
43
export function isNormal(value)
0 ignored issues
show
Unused Code introduced by
The parameter value is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
44
{
45
	return !isUnd(value) && !isNull(value);
46
}
47
48
/**
49
 * @param {(string|number)} value
50
 * @param {boolean=} includeZero = true
51
 * @returns {boolean}
52
 */
53
export function isPosNumeric(value, includeZero = true)
0 ignored issues
show
Unused Code introduced by
The parameter includeZero is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter value is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
54
{
55
	return !isNormal(value) ? false :
56
		(includeZero ? (/^[0-9]*$/).test(value.toString()) : (/^[1-9]+[0-9]*$/).test(value.toString()));
0 ignored issues
show
Best Practice introduced by
If you intend to check if the variable includeZero is declared in the current environment, consider using typeof includeZero === "undefined" instead. This is safe if the variable is not actually declared.
Loading history...
57
}
58
59
/**
60
 * @param {*} value
61
 * @param {number=} defaultValur = 0
62
 * @returns {number}
63
 */
64
export function pInt(value, defaultValur = 0)
0 ignored issues
show
Unused Code introduced by
The parameter defaultValur is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter value is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
65
{
66
	const result = isNormal(value) && '' !== value ? window.parseInt(value, 10) : defaultValur;
0 ignored issues
show
Bug introduced by
The variable result seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.result.
Loading history...
67
	return window.isNaN(result) ? defaultValur : result;
68
}
69
70
/**
71
 * @param {*} value
72
 * @returns {string}
73
 */
74
export function pString(value)
0 ignored issues
show
Unused Code introduced by
The parameter value is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
75
{
76
	return isNormal(value) ? '' + value : '';
77
}
78
79
/**
80
 * @param {*} value
81
 * @returns {boolean}
82
 */
83
export function pBool(value)
0 ignored issues
show
Unused Code introduced by
The parameter value is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
84
{
85
	return !!value;
86
}
87
88
/**
89
 * @param {*} value
90
 * @returns {string}
91
 */
92
export function boolToAjax(value)
0 ignored issues
show
Unused Code introduced by
The parameter value is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
93
{
94
	return value ? '1' : '0';
0 ignored issues
show
Best Practice introduced by
If you intend to check if the variable value is declared in the current environment, consider using typeof value === "undefined" instead. This is safe if the variable is not actually declared.
Loading history...
95
}
96
97
/**
98
 * @param {*} values
99
 * @returns {boolean}
100
 */
101
export function isNonEmptyArray(values)
0 ignored issues
show
Unused Code introduced by
The parameter values is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
102
{
103
	return isArray(values) && 0 < values.length;
104
}
105
106
/**
107
 * @param {string} component
108
 * @returns {string}
109
 */
110
export function encodeURIComponent(component)
0 ignored issues
show
Unused Code introduced by
The parameter component is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
111
{
112
	return window.encodeURIComponent(component);
113
}
114
115
/**
116
 * @param {string} component
117
 * @returns {string}
118
 */
119
export function decodeURIComponent(component)
0 ignored issues
show
Unused Code introduced by
The parameter component is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
120
{
121
	return window.decodeURIComponent(component);
122
}
123
124
/**
125
 * @param {string} url
126
 * @returns {string}
127
 */
128
export function decodeURI(url)
0 ignored issues
show
Unused Code introduced by
The parameter url is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
129
{
130
	return window.decodeURI(url);
131
}
132
133
/**
134
 * @param {string} url
135
 * @returns {string}
136
 */
137
export function encodeURI(url)
0 ignored issues
show
Unused Code introduced by
The parameter url is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
138
{
139
	return window.encodeURI(url);
140
}
141
142
/**
143
 * @param {string} queryString
144
 * @returns {Object}
145
 */
146
export function simpleQueryParser(queryString)
0 ignored issues
show
Unused Code introduced by
The parameter queryString is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
147
{
148
	let
149
		index = 0,
0 ignored issues
show
Bug introduced by
The variable index seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.index.
Loading history...
150
		len = 0,
0 ignored issues
show
Bug introduced by
The variable len seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.len.
Loading history...
151
		temp = null;
0 ignored issues
show
Bug introduced by
The variable temp seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.temp.
Loading history...
152
153
	const
154
		queries = queryString.split('&'),
0 ignored issues
show
Bug introduced by
The variable queries seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.queries.
Loading history...
155
		params = {};
0 ignored issues
show
Bug introduced by
The variable params seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.params.
Loading history...
156
157
	for (len = queries.length; index < len; index++)
158
	{
159
		temp = queries[index].split('=');
160
		params[decodeURIComponent(temp[0])] = decodeURIComponent(temp[1]);
161
	}
162
163
	return params;
164
}
165
166
/**
167
 * @param {number=} len = 32
168
 * @returns {string}
169
 */
170
export function fakeMd5(len = 32)
0 ignored issues
show
Unused Code introduced by
The parameter len is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
171
{
172
	const
173
		line = '0123456789abcdefghijklmnopqrstuvwxyz',
0 ignored issues
show
Bug introduced by
The variable line seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.line.
Loading history...
174
		lineLen = line.length;
0 ignored issues
show
Bug introduced by
The variable lineLen seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.lineLen.
Loading history...
175
176
	len = pInt(len);
0 ignored issues
show
Bug introduced by
The variable len seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.len.
Loading history...
177
178
	let result = '';
0 ignored issues
show
Bug introduced by
The variable result seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.result.
Loading history...
179
	while (result.length < len)
180
	{
181
		result += line.substr(window.Math.round(window.Math.random() * lineLen), 1);
182
	}
183
184
	return result;
185
}
186
187
/**
188
 * @param {string} text
189
 * @returns {string}
190
 */
191
export function encodeHtml(text)
0 ignored issues
show
Unused Code introduced by
The parameter text is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
192
{
193
	return isNormal(text) ? _.escape(text.toString()) : '';
194
}
195
196
/**
197
 * @param {string} text
198
 * @param {number=} len = 100
199
 * @returns {string}
200
 */
201
export function splitPlainText(text, len = 100)
0 ignored issues
show
Unused Code introduced by
The parameter len is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter text is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
202
{
203
	let
204
		prefix = '',
0 ignored issues
show
Bug introduced by
The variable prefix seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.prefix.
Loading history...
205
		subText = '',
0 ignored issues
show
Bug introduced by
The variable subText seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.subText.
Loading history...
206
		result = text,
0 ignored issues
show
Bug introduced by
The variable result seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.result.
Loading history...
207
		spacePos = 0,
0 ignored issues
show
Bug introduced by
The variable spacePos seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.spacePos.
Loading history...
208
		newLinePos = 0;
0 ignored issues
show
Bug introduced by
The variable newLinePos seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.newLinePos.
Loading history...
209
210
	while (result.length > len)
211
	{
212
		subText = result.substring(0, len);
213
		spacePos = subText.lastIndexOf(' ');
214
		newLinePos = subText.lastIndexOf('\n');
215
216
		if (-1 !== newLinePos)
217
		{
218
			spacePos = newLinePos;
219
		}
220
221
		if (-1 === spacePos)
222
		{
223
			spacePos = len;
224
		}
225
226
		prefix += subText.substring(0, spacePos) + '\n';
227
		result = result.substring(spacePos + 1);
228
	}
229
230
	return prefix + result;
231
}
232
233
const timeOutAction = (function() {
234
	const timeOuts = {};
235
	return (action, fFunction, timeOut) => {
236
		timeOuts[action] = isUnd(timeOuts[action]) ? 0 : timeOuts[action];
237
		window.clearTimeout(timeOuts[action]);
238
		timeOuts[action] = window.setTimeout(fFunction, timeOut);
239
	};
240
}());
241
242
const timeOutActionSecond = (function() {
243
	const timeOuts = {};
244
	return (action, fFunction, timeOut) => {
245
		if (!timeOuts[action])
246
		{
247
			timeOuts[action] = window.setTimeout(() => {
248
				fFunction();
249
				timeOuts[action] = 0;
250
			}, timeOut);
251
		}
252
	};
253
}());
254
255
export {timeOutAction, timeOutActionSecond};
256
257
/**
258
 * @returns {boolean}
259
 */
260
export function inFocus()
261
{
262
	try {
263
		if (window.document.activeElement)
264
		{
265
			if (isUnd(window.document.activeElement.__inFocusCache))
266
			{
267
				window.document.activeElement.__inFocusCache = $(window.document.activeElement).is('input,textarea,iframe,.cke_editable');
268
			}
269
270
			return !!window.document.activeElement.__inFocusCache;
271
		}
272
	}
273
	catch (e) {} // eslint-disable-line no-empty
274
275
	return false;
276
}
277
278
/**
279
 * @param {boolean} force
280
 * @returns {void}
281
 */
282
export function removeInFocus(force)
0 ignored issues
show
Unused Code introduced by
The parameter force is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
283
{
284
	if (window.document && window.document.activeElement && window.document.activeElement.blur)
285
	{
286
		try {
287
			const activeEl = $(window.document.activeElement);
0 ignored issues
show
Bug introduced by
The variable activeEl seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.activeEl.
Loading history...
288
			if (activeEl && activeEl.is('input,textarea'))
0 ignored issues
show
Best Practice introduced by
If you intend to check if the variable activeEl is declared in the current environment, consider using typeof activeEl === "undefined" instead. This is safe if the variable is not actually declared.
Loading history...
289
			{
290
				window.document.activeElement.blur();
291
			}
292
			else if (force)
0 ignored issues
show
Best Practice introduced by
If you intend to check if the variable force is declared in the current environment, consider using typeof force === "undefined" instead. This is safe if the variable is not actually declared.
Loading history...
293
			{
294
				window.document.activeElement.blur();
295
			}
296
		}
297
		catch (e) {} // eslint-disable-line no-empty
298
	}
299
}
300
301
/**
302
 * @returns {void}
303
 */
304
export function removeSelection()
305
{
306
	try {
307
		if (window && window.getSelection)
308
		{
309
			const sel = window.getSelection();
0 ignored issues
show
Bug introduced by
The variable sel seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.sel.
Loading history...
310
			if (sel && sel.removeAllRanges)
0 ignored issues
show
Best Practice introduced by
If you intend to check if the variable sel is declared in the current environment, consider using typeof sel === "undefined" instead. This is safe if the variable is not actually declared.
Loading history...
311
			{
312
				sel.removeAllRanges();
313
			}
314
		}
315
		else if (window.document && window.document.selection && window.document.selection.empty)
316
		{
317
			window.document.selection.empty();
318
		}
319
	}
320
	catch (e) {} // eslint-disable-line no-empty
321
}
322
323
/**
324
 * @param {string} prefix
325
 * @param {string} subject
326
 * @returns {string}
327
 */
328
export function replySubjectAdd(prefix, subject)
0 ignored issues
show
Unused Code introduced by
The parameter subject is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter prefix is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
329
{
330
	prefix = trim(prefix.toUpperCase());
0 ignored issues
show
Bug introduced by
The variable prefix seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.prefix.
Loading history...
331
	subject = trim(subject.replace(/[\s]+/g, ' '));
0 ignored issues
show
Bug introduced by
The variable subject seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.subject.
Loading history...
332
333
	let drop = false,
0 ignored issues
show
Bug introduced by
The variable drop seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.drop.
Loading history...
334
		re = 'RE' === prefix,
0 ignored issues
show
Bug introduced by
The variable re seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.re.
Loading history...
335
		fwd = 'FWD' === prefix;
0 ignored issues
show
Bug introduced by
The variable fwd seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.fwd.
Loading history...
336
337
	const
338
		parts = [],
0 ignored issues
show
Bug introduced by
The variable parts seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.parts.
Loading history...
339
		prefixIsRe = !fwd;
0 ignored issues
show
Bug introduced by
The variable prefixIsRe seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.prefixIsRe.
Loading history...
340
341
	if ('' !== subject)
342
	{
343
		_.each(subject.split(':'), (part) => {
344
			const trimmedPart = trim(part);
345
			if (!drop && ((/^(RE|FWD)$/i).test(trimmedPart) || (/^(RE|FWD)[\[\(][\d]+[\]\)]$/i).test(trimmedPart)))
0 ignored issues
show
Best Practice introduced by
If you intend to check if the variable drop is declared in the current environment, consider using typeof drop === "undefined" instead. This is safe if the variable is not actually declared.
Loading history...
346
			{
347
				if (!re)
0 ignored issues
show
Best Practice introduced by
If you intend to check if the variable re is declared in the current environment, consider using typeof re === "undefined" instead. This is safe if the variable is not actually declared.
Loading history...
348
				{
349
					re = !!(/^RE/i).test(trimmedPart);
0 ignored issues
show
Bug introduced by
The variable re seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.re.
Loading history...
350
				}
351
352
				if (!fwd)
0 ignored issues
show
Best Practice introduced by
If you intend to check if the variable fwd is declared in the current environment, consider using typeof fwd === "undefined" instead. This is safe if the variable is not actually declared.
Loading history...
353
				{
354
					fwd = !!(/^FWD/i).test(trimmedPart);
0 ignored issues
show
Bug introduced by
The variable fwd seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.fwd.
Loading history...
355
				}
356
			}
357
			else
358
			{
359
				parts.push(part);
360
				drop = true;
0 ignored issues
show
Bug introduced by
The variable drop seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.drop.
Loading history...
361
			}
362
		});
363
	}
364
365
	if (prefixIsRe)
0 ignored issues
show
Best Practice introduced by
If you intend to check if the variable prefixIsRe is declared in the current environment, consider using typeof prefixIsRe === "undefined" instead. This is safe if the variable is not actually declared.
Loading history...
366
	{
367
		re = false;
368
	}
369
	else
370
	{
371
		fwd = false;
372
	}
373
374
	return trim(
375
		(prefixIsRe ? 'Re: ' : 'Fwd: ') +
376
		(re ? 'Re: ' : '') +
377
		(fwd ? 'Fwd: ' : '') +
378
		trim(parts.join(':'))
379
	);
380
}
381
382
/**
383
 * @param {number} num
384
 * @param {number} dec
385
 * @returns {number}
386
 */
387
export function roundNumber(num, dec)
0 ignored issues
show
Unused Code introduced by
The parameter dec is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter num is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
388
{
389
	return window.Math.round(num * window.Math.pow(10, dec)) / window.Math.pow(10, dec);
390
}
391
392
/**
393
 * @param {(number|string)} sizeInBytes
394
 * @returns {string}
395
 */
396
export function friendlySize(sizeInBytes)
0 ignored issues
show
Unused Code introduced by
The parameter sizeInBytes is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
397
{
398
	sizeInBytes = pInt(sizeInBytes);
0 ignored issues
show
Bug introduced by
The variable sizeInBytes seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.sizeInBytes.
Loading history...
399
400
	switch (true)
401
	{
402
		case 1073741824 <= sizeInBytes:
403
			return roundNumber(sizeInBytes / 1073741824, 1) + 'GB';
404
		case 1048576 <= sizeInBytes:
405
			return roundNumber(sizeInBytes / 1048576, 1) + 'MB';
406
		case 1024 <= sizeInBytes:
407
			return roundNumber(sizeInBytes / 1024, 0) + 'KB';
408
		// no default
409
	}
410
411
	return sizeInBytes + 'B';
412
}
413
414
/**
415
 * @param {string} desc
416
 */
417
export function log(desc)
0 ignored issues
show
Unused Code introduced by
The parameter desc is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
418
{
419
	if (window.console && window.console.log)
420
	{
421
		window.console.log(desc);
422
	}
423
}
424
425
/**
426
 * @param {?} object
427
 * @param {string} methodName
428
 * @param {Array=} params
429
 * @param {number=} delay = 0
430
 */
431
export function delegateRun(object, methodName, params, delay = 0)
0 ignored issues
show
Unused Code introduced by
The parameter methodName is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter object is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter params is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter delay is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
432
{
433
	if (object && object[methodName])
0 ignored issues
show
Best Practice introduced by
If you intend to check if the variable object is declared in the current environment, consider using typeof object === "undefined" instead. This is safe if the variable is not actually declared.
Loading history...
434
	{
435
		delay = pInt(delay);
0 ignored issues
show
Bug introduced by
The variable delay seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.delay.
Loading history...
436
		params = isArray(params) ? params : [];
0 ignored issues
show
Bug introduced by
The variable params seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.params.
Loading history...
437
438
		if (0 >= delay)
439
		{
440
			object[methodName](...params);
441
		}
442
		else
443
		{
444
			_.delay(() => {
445
				object[methodName](...params);
446
			}, delay);
447
		}
448
	}
449
}
450
451
/**
452
 * @param {?} event
453
 */
454
export function killCtrlACtrlS(event)
0 ignored issues
show
Unused Code introduced by
The parameter event is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
455
{
456
	event = event || window.event;
0 ignored issues
show
Bug introduced by
The variable event seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.event.
Loading history...
Best Practice introduced by
If you intend to check if the variable event is declared in the current environment, consider using typeof event === "undefined" instead. This is safe if the variable is not actually declared.
Loading history...
457
	if (event && event.ctrlKey && !event.shiftKey && !event.altKey)
458
	{
459
		const key = event.keyCode || event.which;
0 ignored issues
show
Bug introduced by
The variable key seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.key.
Loading history...
460
		if (key === EventKeyCode.S)
461
		{
462
			event.preventDefault();
463
			return;
464
		}
465
		else if (key === EventKeyCode.A)
466
		{
467
			const sender = event.target || event.srcElement;
0 ignored issues
show
Bug introduced by
The variable sender seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.sender.
Loading history...
468
			if (sender && ('true' === '' + sender.contentEditable ||
0 ignored issues
show
Best Practice introduced by
If you intend to check if the variable sender is declared in the current environment, consider using typeof sender === "undefined" instead. This is safe if the variable is not actually declared.
Loading history...
469
				(sender.tagName && sender.tagName.match(/INPUT|TEXTAREA/i))))
470
			{
471
				return;
472
			}
473
474
			if (window.getSelection)
475
			{
476
				window.getSelection().removeAllRanges();
477
			}
478
			else if (window.document.selection && window.document.selection.clear)
479
			{
480
				window.document.selection.clear();
481
			}
482
483
			event.preventDefault();
484
		}
485
	}
486
}
487
488
/**
489
 * @param {(Object|null|undefined)} context
490
 * @param {Function} fExecute
491
 * @param {(Function|boolean|null)=} fCanExecute = true
492
 * @returns {Function}
493
 */
494
export function createCommandLegacy(context, fExecute, fCanExecute = true)
0 ignored issues
show
Unused Code introduced by
The parameter fCanExecute is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter fExecute is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter context is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
495
{
496
	let fResult = null;
0 ignored issues
show
Bug introduced by
The variable fResult seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.fResult.
Loading history...
497
	const fNonEmpty = (...args) => {
0 ignored issues
show
Bug introduced by
The variable fNonEmpty seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.fNonEmpty.
Loading history...
498
		if (fResult && fResult.canExecute && fResult.canExecute())
0 ignored issues
show
Best Practice introduced by
If you intend to check if the variable fResult is declared in the current environment, consider using typeof fResult === "undefined" instead. This is safe if the variable is not actually declared.
Loading history...
499
		{
500
			fExecute.apply(context, args);
501
		}
502
		return false;
503
	};
504
505
	fResult = fExecute ? fNonEmpty : noop;
0 ignored issues
show
Bug introduced by
The variable fResult seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.fResult.
Loading history...
Best Practice introduced by
If you intend to check if the variable fExecute is declared in the current environment, consider using typeof fExecute === "undefined" instead. This is safe if the variable is not actually declared.
Loading history...
506
	fResult.enabled = ko.observable(true);
507
508
	if (isFunc(fCanExecute))
509
	{
510
		fResult.canExecute = ko.computed(() => fResult.enabled() && fCanExecute.call(context));
511
	}
512
	else
513
	{
514
		fResult.canExecute = ko.computed(() => fResult.enabled() && !!fCanExecute);
0 ignored issues
show
Best Practice introduced by
If you intend to check if the variable fCanExecute is declared in the current environment, consider using typeof fCanExecute === "undefined" instead. This is safe if the variable is not actually declared.
Loading history...
515
	}
516
517
	return fResult;
518
}
519
520
/**
521
 * @param {Function} fExecute
522
 * @param {(Function|boolean|null)=} fCanExecute = true
523
 * @returns {Function}
524
 */
525
export function createCommand(fExecute, fCanExecute = true)
0 ignored issues
show
Unused Code introduced by
The parameter fCanExecute is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter fExecute is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
526
{
527
	return createCommandLegacy(null, fExecute, fCanExecute);
528
}
529
530
/**
531
 * @param {string} theme
532
 * @returns {string}
533
 */
534
export const convertThemeName = _.memoize((theme) => {
0 ignored issues
show
Unused Code introduced by
The constant convertThemeName seems to be never used. Consider removing it.
Loading history...
535
536
	if ('@custom' === theme.substr(-7))
537
	{
538
		theme = trim(theme.substring(0, theme.length - 7));
539
	}
540
541
	return trim(theme.replace(/[^a-zA-Z0-9]+/g, ' ').replace(/([A-Z])/g, ' $1').replace(/[\s]+/g, ' '));
542
});
543
544
/**
545
 * @param {string} name
546
 * @returns {string}
547
 */
548
export function quoteName(name)
0 ignored issues
show
Unused Code introduced by
The parameter name is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
549
{
550
	return name.replace(/["]/g, '\\"');
551
}
552
553
/**
554
 * @returns {number}
555
 */
556
export function microtime()
557
{
558
	return (new window.Date()).getTime();
559
}
560
561
/**
562
 * @returns {number}
563
 */
564
export function timestamp()
565
{
566
	return window.Math.round(microtime() / 1000);
567
}
568
569
/**
570
 *
571
 * @param {string} language
572
 * @param {boolean=} isEng = false
573
 * @returns {string}
574
 */
575
export function convertLangName(language, isEng = false)
0 ignored issues
show
Unused Code introduced by
The parameter language is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter isEng is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
576
{
577
	return require('Common/Translator').i18n('LANGS_NAMES' + (true === isEng ? '_EN' : '') + '/LANG_' +
578
		language.toUpperCase().replace(/[^a-zA-Z0-9]+/g, '_'), null, language);
579
}
580
581
/**
582
 * @returns {object}
583
 */
584
export function draggablePlace()
585
{
586
	return $('<div class="draggablePlace">' +
587
		'<span class="text"></span>&nbsp;' +
588
		'<i class="icon-copy icon-white visible-on-ctrl"></i>' +
589
		'<i class="icon-mail icon-white hidden-on-ctrl"></i>' +
590
		'</div>'
591
	).appendTo('#rl-hidden');
592
}
593
594
/**
595
 * @param {object} domOption
0 ignored issues
show
Documentation introduced by
The parameter domOption does not exist. Did you maybe forget to remove this comment?
Loading history...
596
 * @param {object} item
597
 * @returns {void}
598
 */
599
export function defautOptionsAfterRender(domItem, item)
0 ignored issues
show
Unused Code introduced by
The parameter domItem is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter item is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
600
{
601
	if (item && !isUnd(item.disabled) && domItem)
0 ignored issues
show
Best Practice introduced by
If you intend to check if the variable domItem is declared in the current environment, consider using typeof domItem === "undefined" instead. This is safe if the variable is not actually declared.
Loading history...
Best Practice introduced by
If you intend to check if the variable item is declared in the current environment, consider using typeof item === "undefined" instead. This is safe if the variable is not actually declared.
Loading history...
602
	{
603
		$(domItem)
604
			.toggleClass('disabled', item.disabled)
605
			.prop('disabled', item.disabled);
606
	}
607
}
608
609
/**
610
 * @param {string} title
0 ignored issues
show
Documentation introduced by
The parameter title does not exist. Did you maybe forget to remove this comment?
Loading history...
611
 * @param {Object} body
612
 * @param {boolean} isHtml
0 ignored issues
show
Documentation introduced by
The parameter isHtml does not exist. Did you maybe forget to remove this comment?
Loading history...
613
 * @param {boolean} print
0 ignored issues
show
Documentation introduced by
The parameter print does not exist. Did you maybe forget to remove this comment?
Loading history...
614
 */
615
export function clearBqSwitcher(body)
0 ignored issues
show
Unused Code introduced by
The parameter body is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
616
{
617
	body.find('blockquote.rl-bq-switcher').removeClass('rl-bq-switcher hidden-bq');
618
	body.find('.rlBlockquoteSwitcher').off('.rlBlockquoteSwitcher').remove();
619
	body.find('[data-html-editor-font-wrapper]').removeAttr('data-html-editor-font-wrapper');
620
}
621
622
/**
623
 * @param {object} messageData
0 ignored issues
show
Documentation introduced by
The parameter messageData does not exist. Did you maybe forget to remove this comment?
Loading history...
624
 * @param {Object} body
625
 * @param {boolean} isHtml
626
 * @param {boolean} print
627
 * @returns {void}
628
 */
629
export function previewMessage({title, subject, date, fromCreds, toCreds, toLabel}, body, isHtml, print)
0 ignored issues
show
Unused Code introduced by
The parameter title is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter print is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter fromCreds is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter toCreds is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter body is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter subject is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter isHtml is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter toLabel is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter date is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
630
{
631
	const
632
		win = window.open(''),
0 ignored issues
show
Bug introduced by
The variable win seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.win.
Loading history...
633
		doc = win.document,
0 ignored issues
show
Bug introduced by
The variable doc seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.doc.
Loading history...
634
		bodyClone = body.clone(),
0 ignored issues
show
Bug introduced by
The variable bodyClone seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.bodyClone.
Loading history...
635
		bodyClass = isHtml ? 'html' : 'plain';
0 ignored issues
show
Bug introduced by
The variable bodyClass seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.bodyClass.
Loading history...
Best Practice introduced by
If you intend to check if the variable isHtml is declared in the current environment, consider using typeof isHtml === "undefined" instead. This is safe if the variable is not actually declared.
Loading history...
636
637
	clearBqSwitcher(bodyClone);
638
639
	const html = bodyClone ? bodyClone.html() : '';
0 ignored issues
show
Bug introduced by
The variable html seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.html.
Loading history...
Best Practice introduced by
If you intend to check if the variable bodyClone is declared in the current environment, consider using typeof bodyClone === "undefined" instead. This is safe if the variable is not actually declared.
Loading history...
640
641
	doc.write(require('Html/PreviewMessage.html')
642
		.replace('{{title}}', encodeHtml(title))
643
		.replace('{{subject}}', encodeHtml(subject))
644
		.replace('{{date}}', encodeHtml(date))
645
		.replace('{{fromCreds}}', encodeHtml(fromCreds))
646
		.replace('{{toCreds}}', encodeHtml(toCreds))
647
		.replace('{{toLabel}}', encodeHtml(toLabel))
648
		.replace('{{bodyClass}}', bodyClass)
649
		.replace('{{html}}', html)
650
	);
651
652
	doc.close();
653
654
	if (print)
0 ignored issues
show
Best Practice introduced by
If you intend to check if the variable print is declared in the current environment, consider using typeof print === "undefined" instead. This is safe if the variable is not actually declared.
Loading history...
655
	{
656
		window.setTimeout(() => win.print(), 100);
657
	}
658
}
659
660
/**
661
 * @param {Function} fCallback
662
 * @param {?} koTrigger
663
 * @param {?} context = null
664
 * @param {number=} timer = 1000
665
 * @returns {Function}
666
 */
667
export function settingsSaveHelperFunction(fCallback, koTrigger, context = null, timer = 1000)
0 ignored issues
show
Unused Code introduced by
The parameter context is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter timer is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter koTrigger is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter fCallback is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
668
{
669
	timer = pInt(timer);
0 ignored issues
show
Bug introduced by
The variable timer seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.timer.
Loading history...
670
	return (type, data, cached, requestAction, requestParameters) => {
671
		koTrigger.call(context, data && data.Result ? SaveSettingsStep.TrueResult : SaveSettingsStep.FalseResult);
672
		if (fCallback)
0 ignored issues
show
Best Practice introduced by
If you intend to check if the variable fCallback is declared in the current environment, consider using typeof fCallback === "undefined" instead. This is safe if the variable is not actually declared.
Loading history...
673
		{
674
			fCallback.call(context, type, data, cached, requestAction, requestParameters);
675
		}
676
		_.delay(() => {
677
			koTrigger.call(context, SaveSettingsStep.Idle);
678
		}, timer);
679
	};
680
}
681
682
/**
683
 * @param {object} koTrigger
684
 * @param {mixed} context
685
 * @returns {mixed}
686
 */
687
export function settingsSaveHelperSimpleFunction(koTrigger, context)
0 ignored issues
show
Unused Code introduced by
The parameter context is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter koTrigger is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
688
{
689
	return settingsSaveHelperFunction(null, koTrigger, context, 1000);
690
}
691
692
/**
693
 * @param {object} remote
694
 * @param {string} settingName
695
 * @param {string} type
696
 * @param {function} fTriggerFunction
697
 * @returns {function}
698
 */
699
export function settingsSaveHelperSubscribeFunction(remote, settingName, type, fTriggerFunction)
0 ignored issues
show
Unused Code introduced by
The parameter settingName is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter type is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter fTriggerFunction is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter remote is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
700
{
701
	return (value) => {
702
703
		if (remote)
0 ignored issues
show
Best Practice introduced by
If you intend to check if the variable remote is declared in the current environment, consider using typeof remote === "undefined" instead. This is safe if the variable is not actually declared.
Loading history...
704
		{
705
			switch (type)
706
			{
707
				case 'bool':
708
				case 'boolean':
709
					value = value ? '1' : '0';
710
					break;
711
				case 'int':
712
				case 'integer':
713
				case 'number':
714
					value = pInt(value);
715
					break;
716
				case 'trim':
717
					value = trim(value);
718
					break;
719
				default:
720
					value = pString(value);
721
					break;
722
			}
723
724
			const data = {};
725
			data[settingName] = value;
726
727
			if (remote.saveAdminConfig)
728
			{
729
				remote.saveAdminConfig(fTriggerFunction || null, data);
0 ignored issues
show
Best Practice introduced by
If you intend to check if the variable fTriggerFunction is declared in the current environment, consider using typeof fTriggerFunction === "undefined" instead. This is safe if the variable is not actually declared.
Loading history...
730
			}
731
			else if (remote.saveSettings)
732
			{
733
				remote.saveSettings(fTriggerFunction || null, data);
734
			}
735
		}
736
	};
737
}
738
739
/**
740
 * @param {string} html
741
 * @returns {string}
742
 */
743
export function findEmailAndLinks(html)
0 ignored issues
show
Unused Code introduced by
The parameter html is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
744
{
745
//	return html;
746
	return Autolinker.link(html, {
747
		newWindow: true,
748
		stripPrefix: false,
749
		urls: true,
750
		email: true,
751
		twitter: false,
752
		phone: false,
753
		hashtag: false,
754
		replaceFn: function(autolinker, match) {
755
			return !(autolinker && match && 'url' === match.getType() && match.matchedText && 0 !== match.matchedText.indexOf('http'));
756
		}
757
	});
758
}
759
760
/**
761
 * @param {string} html
762
 * @returns {string}
763
 */
764
export function htmlToPlain(html)
0 ignored issues
show
Unused Code introduced by
The parameter html is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
765
{
766
	let
767
		pos = 0,
0 ignored issues
show
Bug introduced by
The variable pos seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.pos.
Loading history...
768
		limit = 0,
0 ignored issues
show
Bug introduced by
The variable limit seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.limit.
Loading history...
769
		iP1 = 0,
0 ignored issues
show
Bug introduced by
The variable iP1 seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.iP1.
Loading history...
770
		iP2 = 0,
0 ignored issues
show
Bug introduced by
The variable iP2 seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.iP2.
Loading history...
771
		iP3 = 0,
0 ignored issues
show
Bug introduced by
The variable iP3 seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.iP3.
Loading history...
772
773
		text = '';
0 ignored issues
show
Bug introduced by
The variable text seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.text.
Loading history...
774
775
	const
776
		convertBlockquote = (blockquoteText) => {
0 ignored issues
show
Bug introduced by
The variable convertBlockquote seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.convertBlockquote.
Loading history...
777
			blockquoteText = '> ' + trim(blockquoteText).replace(/\n/gm, '\n> ');
778
			return blockquoteText.replace(/(^|\n)([> ]+)/gm,
779
				(...args) => (args && 2 < args.length ? args[1] + trim(args[2].replace(/[\s]/g, '')) + ' ' : ''));
0 ignored issues
show
introduced by
This code is unreachable and can thus be removed without consequences.
Loading history...
Bug introduced by
The variable args seems to be never initialized.
Loading history...
780
		},
781
		convertDivs = (...args) => {
0 ignored issues
show
Bug introduced by
The variable convertDivs seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.convertDivs.
Loading history...
782
			if (args && 1 < args.length)
783
			{
784
				let divText = trim(args[1]);
785
				if (0 < divText.length)
786
				{
787
					divText = divText.replace(/<div[^>]*>([\s\S\r\n]*)<\/div>/gmi, convertDivs);
788
					divText = '\n' + trim(divText) + '\n';
789
				}
790
791
				return divText;
792
			}
793
794
			return '';
795
		},
796
		convertPre = (...args) => (args && 1 < args.length ? args[1].toString().replace(/[\n]/gm, '<br />').replace(/[\r]/gm, '') : ''),
0 ignored issues
show
introduced by
This code is unreachable and can thus be removed without consequences.
Loading history...
Bug introduced by
The variable args seems to be never initialized.
Loading history...
Bug introduced by
The variable convertPre seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.convertPre.
Loading history...
797
		fixAttibuteValue = (...args) => (args && 1 < args.length ? '' + args[1] + _.escape(args[2]) : ''),
0 ignored issues
show
Bug introduced by
The variable args seems to be never initialized.
Loading history...
introduced by
This code is unreachable and can thus be removed without consequences.
Loading history...
Bug introduced by
The variable fixAttibuteValue seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.fixAttibuteValue.
Loading history...
798
		convertLinks = (...args) => (args && 1 < args.length ? trim(args[1]) : '');
0 ignored issues
show
Bug introduced by
The variable args seems to be never initialized.
Loading history...
introduced by
This code is unreachable and can thus be removed without consequences.
Loading history...
Bug introduced by
The variable convertLinks seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.convertLinks.
Loading history...
799
800
	text = html
0 ignored issues
show
Bug introduced by
The variable text seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.text.
Loading history...
801
		.replace(/<p[^>]*><\/p>/gi, '')
802
		.replace(/<pre[^>]*>([\s\S\r\n\t]*)<\/pre>/gmi, convertPre)
803
		.replace(/[\s]+/gm, ' ')
804
		.replace(/((?:href|data)\s?=\s?)("[^"]+?"|'[^']+?')/gmi, fixAttibuteValue)
805
		.replace(/<br[^>]*>/gmi, '\n')
806
		.replace(/<\/h[\d]>/gi, '\n')
807
		.replace(/<\/p>/gi, '\n\n')
808
		.replace(/<ul[^>]*>/gmi, '\n')
809
		.replace(/<\/ul>/gi, '\n')
810
		.replace(/<li[^>]*>/gmi, ' * ')
811
		.replace(/<\/li>/gi, '\n')
812
		.replace(/<\/td>/gi, '\n')
813
		.replace(/<\/tr>/gi, '\n')
814
		.replace(/<hr[^>]*>/gmi, '\n_______________________________\n\n')
815
		.replace(/<div[^>]*>([\s\S\r\n]*)<\/div>/gmi, convertDivs)
816
		.replace(/<blockquote[^>]*>/gmi, '\n__bq__start__\n')
817
		.replace(/<\/blockquote>/gmi, '\n__bq__end__\n')
818
		.replace(/<a [^>]*>([\s\S\r\n]*?)<\/a>/gmi, convertLinks)
819
		.replace(/<\/div>/gi, '\n')
820
		.replace(/&nbsp;/gi, ' ')
821
		.replace(/&quot;/gi, '"')
822
		.replace(/<[^>]*>/gm, '');
823
824
	text = $div.html(text).text();
825
826
	text = text
827
		.replace(/\n[ \t]+/gm, '\n')
828
		.replace(/[\n]{3,}/gm, '\n\n')
829
		.replace(/&gt;/gi, '>')
830
		.replace(/&lt;/gi, '<')
831
		.replace(/&amp;/gi, '&');
832
833
	text = splitPlainText(trim(text));
834
835
	pos = 0;
0 ignored issues
show
Bug introduced by
The variable pos seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.pos.
Loading history...
836
	limit = 800;
0 ignored issues
show
Bug introduced by
The variable limit seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.limit.
Loading history...
837
838
	while (0 < limit)
0 ignored issues
show
Bug introduced by
The condition 0 < limit seems to be always true, making it impossible for the loop to be exited. Are you sure about that?
Loading history...
839
	{
840
		limit -= 1;
841
		iP1 = text.indexOf('__bq__start__', pos);
0 ignored issues
show
Bug introduced by
The variable iP1 seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.iP1.
Loading history...
842
		if (-1 < iP1)
843
		{
844
			iP2 = text.indexOf('__bq__start__', iP1 + 5);
0 ignored issues
show
Bug introduced by
The variable iP2 seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.iP2.
Loading history...
845
			iP3 = text.indexOf('__bq__end__', iP1 + 5);
0 ignored issues
show
Bug introduced by
The variable iP3 seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.iP3.
Loading history...
846
847
			if ((-1 === iP2 || iP3 < iP2) && iP1 < iP3)
848
			{
849
				text = text.substring(0, iP1) +
850
					convertBlockquote(text.substring(iP1 + 13, iP3)) +
851
					text.substring(iP3 + 11);
852
853
				pos = 0;
854
			}
855
			else if (-1 < iP2 && iP2 < iP3)
856
			{
857
				pos = iP2 - 1;
858
			}
859
			else
860
			{
861
				pos = 0;
862
			}
863
		}
864
		else
865
		{
866
			break;
867
		}
868
	}
869
870
	text = text
871
		.replace(/__bq__start__/gm, '')
872
		.replace(/__bq__end__/gm, '');
873
874
	return text;
875
}
876
877
/**
878
 * @param {string} plain
879
 * @param {boolean} findEmailAndLinksInText = false
880
 * @returns {string}
881
 */
882
export function plainToHtml(plain, findEmailAndLinksInText = false)
0 ignored issues
show
Unused Code introduced by
The parameter plain is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter findEmailAndLinksInText is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
883
{
884
	plain = plain.toString().replace(/\r/g, '');
0 ignored issues
show
Bug introduced by
The variable plain seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.plain.
Loading history...
885
	plain = plain.replace(/^>[> ]>+/gm, ([match]) => (match ? match.replace(/[ ]+/g, '') : match));
0 ignored issues
show
introduced by
This code is unreachable and can thus be removed without consequences.
Loading history...
Bug introduced by
The variable match seems to be never initialized.
Loading history...
Bug introduced by
The variable plain seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.plain.
Loading history...
886
887
	let
888
		bIn = false,
0 ignored issues
show
Bug introduced by
The variable bIn seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.bIn.
Loading history...
889
		bDo = true,
0 ignored issues
show
Bug introduced by
The variable bDo seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.bDo.
Loading history...
890
		bStart = true,
0 ignored issues
show
Bug introduced by
The variable bStart seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.bStart.
Loading history...
891
		aNextText = [],
0 ignored issues
show
Bug introduced by
The variable aNextText seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.aNextText.
Loading history...
892
		sLine = '',
0 ignored issues
show
Bug introduced by
The variable sLine seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.sLine.
Loading history...
893
		iIndex = 0,
0 ignored issues
show
Bug introduced by
The variable iIndex seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.iIndex.
Loading history...
894
		aText = plain.split('\n');
0 ignored issues
show
Bug introduced by
The variable aText seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.aText.
Loading history...
895
896
	do
897
	{
898
		bDo = false;
899
		aNextText = [];
900
		for (iIndex = 0; iIndex < aText.length; iIndex++)
901
		{
902
			sLine = aText[iIndex];
903
			bStart = '>' === sLine.substr(0, 1);
904
			if (bStart && !bIn)
0 ignored issues
show
Best Practice introduced by
If you intend to check if the variable bStart is declared in the current environment, consider using typeof bStart === "undefined" instead. This is safe if the variable is not actually declared.
Loading history...
Best Practice introduced by
If you intend to check if the variable bIn is declared in the current environment, consider using typeof bIn === "undefined" instead. This is safe if the variable is not actually declared.
Loading history...
905
			{
906
				bDo = true;
907
				bIn = true;
908
				aNextText.push('~~~blockquote~~~');
909
				aNextText.push(sLine.substr(1));
910
			}
911
			else if (!bStart && bIn)
912
			{
913
				if ('' !== sLine)
914
				{
915
					bIn = false;
916
					aNextText.push('~~~/blockquote~~~');
917
					aNextText.push(sLine);
918
				}
919
				else
920
				{
921
					aNextText.push(sLine);
922
				}
923
			}
924
			else if (bStart && bIn)
925
			{
926
				aNextText.push(sLine.substr(1));
927
			}
928
			else
929
			{
930
				aNextText.push(sLine);
931
			}
932
		}
933
934
		if (bIn)
935
		{
936
			bIn = false;
937
			aNextText.push('~~~/blockquote~~~');
938
		}
939
940
		aText = aNextText;
941
	}
942
	while (bDo);
943
944
	plain = aText.join('\n');
945
946
	plain = plain
947
//			.replace(/~~~\/blockquote~~~\n~~~blockquote~~~/g, '\n')
948
		.replace(/&/g, '&amp;')
949
		.replace(/>/g, '&gt;').replace(/</g, '&lt;')
950
		.replace(/~~~blockquote~~~[\s]*/g, '<blockquote>')
951
		.replace(/[\s]*~~~\/blockquote~~~/g, '</blockquote>')
952
		.replace(/\n/g, '<br />');
953
954
	return findEmailAndLinksInText ? findEmailAndLinks(plain) : plain;
0 ignored issues
show
Best Practice introduced by
If you intend to check if the variable findEmailAndLinksInText is declared in the current environment, consider using typeof findEmailAndLinksInText === "undefined" instead. This is safe if the variable is not actually declared.
Loading history...
955
}
956
957
window['rainloop_Utils_htmlToPlain'] = htmlToPlain; // eslint-disable-line dot-notation
958
window['rainloop_Utils_plainToHtml'] = plainToHtml; // eslint-disable-line dot-notation
959
960
/**
961
 * @param {Array} aSystem
962
 * @param {Array} aList
963
 * @param {Array=} aDisabled
964
 * @param {Array=} aHeaderLines
965
 * @param {?number=} iUnDeep
966
 * @param {Function=} fDisableCallback
967
 * @param {Function=} fVisibleCallback
968
 * @param {Function=} fRenameCallback
969
 * @param {boolean=} bSystem
970
 * @param {boolean=} bBuildUnvisible
971
 * @returns {Array}
972
 */
973
export function folderListOptionsBuilder(aSystem, aList, aDisabled, aHeaderLines,
0 ignored issues
show
Unused Code introduced by
The parameter aHeaderLines is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter aDisabled is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter aList is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter aSystem is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
974
	iUnDeep, fDisableCallback, fVisibleCallback, fRenameCallback, bSystem, bBuildUnvisible)
0 ignored issues
show
Unused Code introduced by
The parameter fDisableCallback is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter bSystem is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter fVisibleCallback is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter iUnDeep is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter fRenameCallback is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter bBuildUnvisible is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
975
{
976
	let
977
		/**
978
		 * @type {?FolderModel}
979
		 */
980
		oItem = null,
0 ignored issues
show
Bug introduced by
The variable oItem seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.oItem.
Loading history...
981
		bSep = false,
0 ignored issues
show
Bug introduced by
The variable bSep seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.bSep.
Loading history...
982
		iIndex = 0,
0 ignored issues
show
Bug introduced by
The variable iIndex seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.iIndex.
Loading history...
983
		iLen = 0,
0 ignored issues
show
Bug introduced by
The variable iLen seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.iLen.
Loading history...
984
		aResult = [];
0 ignored issues
show
Bug introduced by
The variable aResult seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.aResult.
Loading history...
985
986
	const sDeepPrefix = '\u00A0\u00A0\u00A0';
0 ignored issues
show
Bug introduced by
The variable sDeepPrefix seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.sDeepPrefix.
Loading history...
987
988
	bBuildUnvisible = isUnd(bBuildUnvisible) ? false : !!bBuildUnvisible;
0 ignored issues
show
Bug introduced by
The variable bBuildUnvisible seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.bBuildUnvisible.
Loading history...
989
	bSystem = !isNormal(bSystem) ? 0 < aSystem.length : bSystem;
0 ignored issues
show
Bug introduced by
The variable bSystem seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.bSystem.
Loading history...
990
	iUnDeep = !isNormal(iUnDeep) ? 0 : iUnDeep;
0 ignored issues
show
Bug introduced by
The variable iUnDeep seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.iUnDeep.
Loading history...
991
	fDisableCallback = isNormal(fDisableCallback) ? fDisableCallback : null;
0 ignored issues
show
Bug introduced by
The variable fDisableCallback seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.fDisableCallback.
Loading history...
992
	fVisibleCallback = isNormal(fVisibleCallback) ? fVisibleCallback : null;
0 ignored issues
show
Bug introduced by
The variable fVisibleCallback seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.fVisibleCallback.
Loading history...
993
	fRenameCallback = isNormal(fRenameCallback) ? fRenameCallback : null;
0 ignored issues
show
Bug introduced by
The variable fRenameCallback seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.fRenameCallback.
Loading history...
994
995
	if (!isArray(aDisabled))
996
	{
997
		aDisabled = [];
0 ignored issues
show
Bug introduced by
The variable aDisabled seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.aDisabled.
Loading history...
998
	}
999
1000
	if (!isArray(aHeaderLines))
1001
	{
1002
		aHeaderLines = [];
0 ignored issues
show
Bug introduced by
The variable aHeaderLines seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.aHeaderLines.
Loading history...
1003
	}
1004
1005
	for (iIndex = 0, iLen = aHeaderLines.length; iIndex < iLen; iIndex++)
1006
	{
1007
		aResult.push({
1008
			id: aHeaderLines[iIndex][0],
1009
			name: aHeaderLines[iIndex][1],
1010
			system: false,
1011
			seporator: false,
1012
			disabled: false
1013
		});
1014
	}
1015
1016
	bSep = true;
1017
	for (iIndex = 0, iLen = aSystem.length; iIndex < iLen; iIndex++)
1018
	{
1019
		oItem = aSystem[iIndex];
1020
		if (fVisibleCallback ? fVisibleCallback(oItem) : true)
0 ignored issues
show
Best Practice introduced by
If you intend to check if the variable fVisibleCallback is declared in the current environment, consider using typeof fVisibleCallback === "undefined" instead. This is safe if the variable is not actually declared.
Loading history...
1021
		{
1022
			if (bSep && 0 < aResult.length)
0 ignored issues
show
Best Practice introduced by
If you intend to check if the variable bSep is declared in the current environment, consider using typeof bSep === "undefined" instead. This is safe if the variable is not actually declared.
Loading history...
1023
			{
1024
				aResult.push({
1025
					id: '---',
1026
					name: '---',
1027
					system: false,
1028
					seporator: true,
1029
					disabled: true
1030
				});
1031
			}
1032
1033
			bSep = false;
1034
			aResult.push({
1035
				id: oItem.fullNameRaw,
1036
				name: fRenameCallback ? fRenameCallback(oItem) : oItem.name(),
0 ignored issues
show
Best Practice introduced by
If you intend to check if the variable fRenameCallback is declared in the current environment, consider using typeof fRenameCallback === "undefined" instead. This is safe if the variable is not actually declared.
Loading history...
1037
				system: true,
1038
				seporator: false,
1039
				disabled: !oItem.selectable || -1 < inArray(oItem.fullNameRaw, aDisabled) ||
1040
					(fDisableCallback ? fDisableCallback(oItem) : false)
0 ignored issues
show
Best Practice introduced by
If you intend to check if the variable fDisableCallback is declared in the current environment, consider using typeof fDisableCallback === "undefined" instead. This is safe if the variable is not actually declared.
Loading history...
1041
			});
1042
		}
1043
	}
1044
1045
	bSep = true;
1046
	for (iIndex = 0, iLen = aList.length; iIndex < iLen; iIndex++)
1047
	{
1048
		oItem = aList[iIndex];
1049
//			if (oItem.subScribed() || !oItem.existen || bBuildUnvisible)
1050
		if ((oItem.subScribed() || !oItem.existen || bBuildUnvisible) && (oItem.selectable || oItem.hasSubScribedSubfolders()))
0 ignored issues
show
Best Practice introduced by
If you intend to check if the variable bBuildUnvisible is declared in the current environment, consider using typeof bBuildUnvisible === "undefined" instead. This is safe if the variable is not actually declared.
Loading history...
1051
		{
1052
			if (fVisibleCallback ? fVisibleCallback(oItem) : true)
1053
			{
1054
				if (FolderType.User === oItem.type() || !bSystem || oItem.hasSubScribedSubfolders())
0 ignored issues
show
Best Practice introduced by
If you intend to check if the variable bSystem is declared in the current environment, consider using typeof bSystem === "undefined" instead. This is safe if the variable is not actually declared.
Loading history...
1055
				{
1056
					if (bSep && 0 < aResult.length)
1057
					{
1058
						aResult.push({
1059
							id: '---',
1060
							name: '---',
1061
							system: false,
1062
							seporator: true,
1063
							disabled: true
1064
						});
1065
					}
1066
1067
					bSep = false;
1068
					aResult.push({
1069
						id: oItem.fullNameRaw,
1070
						name: (new window.Array(oItem.deep + 1 - iUnDeep)).join(sDeepPrefix) +
1071
							(fRenameCallback ? fRenameCallback(oItem) : oItem.name()),
1072
						system: false,
1073
						seporator: false,
1074
						disabled: !oItem.selectable || -1 < inArray(oItem.fullNameRaw, aDisabled) ||
1075
							(fDisableCallback ? fDisableCallback(oItem) : false)
1076
					});
1077
				}
1078
			}
1079
		}
1080
1081
		if (oItem.subScribed() && 0 < oItem.subFolders().length)
1082
		{
1083
			aResult = aResult.concat(folderListOptionsBuilder([], oItem.subFolders(), aDisabled, [],
1084
				iUnDeep, fDisableCallback, fVisibleCallback, fRenameCallback, bSystem, bBuildUnvisible));
1085
		}
1086
	}
1087
1088
	return aResult;
1089
}
1090
1091
/**
1092
 * @param {object} element
1093
 * @returns {void}
1094
 */
1095
export function selectElement(element)
0 ignored issues
show
Unused Code introduced by
The parameter element is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
1096
{
1097
	let
1098
		sel = null,
0 ignored issues
show
Bug introduced by
The variable sel seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.sel.
Loading history...
1099
		range = null;
0 ignored issues
show
Bug introduced by
The variable range seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.range.
Loading history...
1100
1101
	if (window.getSelection)
1102
	{
1103
		sel = window.getSelection();
1104
		sel.removeAllRanges();
1105
		range = window.document.createRange();
1106
		range.selectNodeContents(element);
1107
		sel.addRange(range);
1108
	}
1109
	else if (window.document.selection)
1110
	{
1111
		range = window.document.body.createTextRange();
1112
		range.moveToElementText(element);
1113
		range.select();
1114
	}
1115
}
1116
1117
export const detectDropdownVisibility = _.debounce(() => {
0 ignored issues
show
Unused Code introduced by
The constant detectDropdownVisibility seems to be never used. Consider removing it.
Loading history...
1118
	dropdownVisibility(!!_.find(GlobalsData.aBootstrapDropdowns, (item) => item.hasClass('open')));
1119
}, 50);
1120
1121
/**
1122
 * @param {boolean=} delay = false
1123
 */
1124
export function triggerAutocompleteInputChange(delay = false) {
0 ignored issues
show
Unused Code introduced by
The parameter delay is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
1125
1126
	const fFunc = () => {
0 ignored issues
show
Bug introduced by
The variable fFunc seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.fFunc.
Loading history...
1127
		$('.checkAutocomplete').trigger('change');
1128
	};
1129
1130
	if (delay)
0 ignored issues
show
Best Practice introduced by
If you intend to check if the variable delay is declared in the current environment, consider using typeof delay === "undefined" instead. This is safe if the variable is not actually declared.
Loading history...
1131
	{
1132
		_.delay(fFunc, 100);
1133
	}
1134
	else
1135
	{
1136
		fFunc();
1137
	}
1138
}
1139
1140
const configurationScriptTagCache = {};
0 ignored issues
show
Unused Code introduced by
The constant configurationScriptTagCache seems to be never used. Consider removing it.
Loading history...
1141
1142
/**
1143
 * @param {string} configuration
1144
 * @returns {object}
1145
 */
1146
export function getConfigurationFromScriptTag(configuration)
0 ignored issues
show
Unused Code introduced by
The parameter configuration is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
1147
{
1148
	if (!configurationScriptTagCache[configuration])
1149
	{
1150
		configurationScriptTagCache[configuration] = $('script[type="application/json"][data-configuration="' + configuration + '"]');
1151
	}
1152
1153
	try
1154
	{
1155
		return JSON.parse(configurationScriptTagCache[configuration].text());
1156
	}
1157
	catch (e) {} // eslint-disable-line no-empty
1158
1159
	return {};
1160
}
1161
1162
/**
1163
 * @param {mixed} mPropOrValue
0 ignored issues
show
Documentation introduced by
The parameter mPropOrValue does not exist. Did you maybe forget to remove this comment?
Loading history...
1164
 * @param {mixed} value
1165
 */
1166
export function disposeOne(propOrValue, value)
0 ignored issues
show
Unused Code introduced by
The parameter propOrValue is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter value is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
1167
{
1168
	const disposable = value || propOrValue;
0 ignored issues
show
Best Practice introduced by
If you intend to check if the variable propOrValue is declared in the current environment, consider using typeof propOrValue === "undefined" instead. This is safe if the variable is not actually declared.
Loading history...
Bug introduced by
The variable disposable seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.disposable.
Loading history...
Best Practice introduced by
If you intend to check if the variable value is declared in the current environment, consider using typeof value === "undefined" instead. This is safe if the variable is not actually declared.
Loading history...
1169
	if (disposable && 'function' === typeof disposable.dispose)
0 ignored issues
show
Best Practice introduced by
If you intend to check if the variable disposable is declared in the current environment, consider using typeof disposable === "undefined" instead. This is safe if the variable is not actually declared.
Loading history...
1170
	{
1171
		disposable.dispose();
1172
	}
1173
}
1174
1175
/**
1176
 * @param {Object} object
1177
 */
1178
export function disposeObject(object)
0 ignored issues
show
Unused Code introduced by
The parameter object is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
1179
{
1180
	if (object)
0 ignored issues
show
Best Practice introduced by
If you intend to check if the variable object is declared in the current environment, consider using typeof object === "undefined" instead. This is safe if the variable is not actually declared.
Loading history...
1181
	{
1182
		if (isArray(object.disposables))
1183
		{
1184
			_.each(object.disposables, disposeOne);
1185
		}
1186
1187
		ko.utils.objectForEach(object, disposeOne);
1188
	}
1189
}
1190
1191
/**
1192
 * @param {Object|Array} objectOrObjects
1193
 * @returns {void}
1194
 */
1195
export function delegateRunOnDestroy(objectOrObjects)
0 ignored issues
show
Unused Code introduced by
The parameter objectOrObjects is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
1196
{
1197
	if (objectOrObjects)
0 ignored issues
show
Best Practice introduced by
If you intend to check if the variable objectOrObjects is declared in the current environment, consider using typeof objectOrObjects === "undefined" instead. This is safe if the variable is not actually declared.
Loading history...
1198
	{
1199
		if (isArray(objectOrObjects))
1200
		{
1201
			_.each(objectOrObjects, (item) => {
1202
				delegateRunOnDestroy(item);
1203
			});
1204
		}
1205
		else if (objectOrObjects && objectOrObjects.onDestroy)
0 ignored issues
show
Best Practice introduced by
If you intend to check if the variable objectOrObjects is declared in the current environment, consider using typeof objectOrObjects === "undefined" instead. This is safe if the variable is not actually declared.
Loading history...
1206
		{
1207
			objectOrObjects.onDestroy();
1208
		}
1209
	}
1210
}
1211
1212
/**
1213
 * @param {object} $styleTag
1214
 * @param {string} css
1215
 * @returns {boolean}
1216
 */
1217
export function appendStyles($styleTag, css)
0 ignored issues
show
Unused Code introduced by
The parameter css is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter $styleTag is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
1218
{
1219
	if ($styleTag && $styleTag[0])
0 ignored issues
show
Best Practice introduced by
If you intend to check if the variable $styleTag is declared in the current environment, consider using typeof $styleTag === "undefined" instead. This is safe if the variable is not actually declared.
Loading history...
1220
	{
1221
		if ($styleTag[0].styleSheet && !isUnd($styleTag[0].styleSheet.cssText))
1222
		{
1223
			$styleTag[0].styleSheet.cssText = css;
1224
		}
1225
		else
1226
		{
1227
			$styleTag.text(css);
1228
		}
1229
1230
		return true;
1231
	}
1232
1233
	return false;
1234
}
1235
1236
let
1237
	__themeTimer = 0,
0 ignored issues
show
Unused Code introduced by
The variable __themeTimer seems to be never used. Consider removing it.
Loading history...
1238
	__themeAjax = null;
0 ignored issues
show
Unused Code introduced by
The variable __themeAjax seems to be never used. Consider removing it.
Loading history...
1239
1240
/**
1241
 * @param {string} value
1242
 * @param {function=} themeTrigger = noop
1243
 * @returns {void}
1244
 */
1245
export function changeTheme(value, themeTrigger = noop)
0 ignored issues
show
Unused Code introduced by
The parameter value is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter themeTrigger is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
1246
{
1247
	const
1248
		themeLink = $('#app-theme-link'),
0 ignored issues
show
Bug introduced by
The variable themeLink seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.themeLink.
Loading history...
1249
		clearTimer = () => {
0 ignored issues
show
Bug introduced by
The variable clearTimer seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.clearTimer.
Loading history...
1250
			__themeTimer = window.setTimeout(() => themeTrigger(SaveSettingsStep.Idle), 1000);
0 ignored issues
show
Bug introduced by
The variable __themeTimer seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.__themeTimer.
Loading history...
1251
			__themeAjax = null;
0 ignored issues
show
Bug introduced by
The variable __themeAjax seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.__themeAjax.
Loading history...
1252
		};
1253
1254
	let
1255
		themeStyle = $('#app-theme-style'),
0 ignored issues
show
Bug introduced by
The variable themeStyle seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.themeStyle.
Loading history...
1256
		url = themeLink.attr('href');
0 ignored issues
show
Bug introduced by
The variable url seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.url.
Loading history...
1257
1258
	if (!url)
0 ignored issues
show
Best Practice introduced by
If you intend to check if the variable url is declared in the current environment, consider using typeof url === "undefined" instead. This is safe if the variable is not actually declared.
Loading history...
1259
	{
1260
		url = themeStyle.attr('data-href');
1261
	}
1262
1263
	if (url)
1264
	{
1265
		url = url.toString().replace(/\/-\/[^\/]+\/\-\//, '/-/' + value + '/-/');
1266
		url = url.toString().replace(/\/Css\/[^\/]+\/User\//, '/Css/0/User/');
1267
		url = url.toString().replace(/\/Hash\/[^\/]+\//, '/Hash/-/');
1268
1269
		if ('Json/' !== url.substring(url.length - 5, url.length))
1270
		{
1271
			url += 'Json/';
1272
		}
1273
1274
		window.clearTimeout(__themeTimer);
1275
1276
		themeTrigger(SaveSettingsStep.Animate);
1277
1278
		if (__themeAjax && __themeAjax.abort)
0 ignored issues
show
Best Practice introduced by
If you intend to check if the variable __themeAjax is declared in the current environment, consider using typeof __themeAjax === "undefined" instead. This is safe if the variable is not actually declared.
Loading history...
1279
		{
1280
			__themeAjax.abort();
1281
		}
1282
1283
		__themeAjax = $.ajax({
0 ignored issues
show
Bug introduced by
The variable __themeAjax seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.__themeAjax.
Loading history...
1284
			url: url,
1285
			dataType: 'json'
1286
		}).then((data) => {
1287
1288
			if (data && isArray(data) && 2 === data.length)
1289
			{
1290
				if (themeLink && themeLink[0] && (!themeStyle || !themeStyle[0]))
0 ignored issues
show
Best Practice introduced by
If you intend to check if the variable themeStyle is declared in the current environment, consider using typeof themeStyle === "undefined" instead. This is safe if the variable is not actually declared.
Loading history...
Best Practice introduced by
If you intend to check if the variable themeLink is declared in the current environment, consider using typeof themeLink === "undefined" instead. This is safe if the variable is not actually declared.
Loading history...
1291
				{
1292
					themeStyle = $('<style id="app-theme-style"></style>');
0 ignored issues
show
Bug introduced by
The variable themeStyle seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.themeStyle.
Loading history...
1293
					themeLink.after(themeStyle);
1294
					themeLink.remove();
1295
				}
1296
1297
				if (themeStyle && themeStyle[0])
1298
				{
1299
					if (appendStyles(themeStyle, data[1]))
1300
					{
1301
						themeStyle.attr('data-href', url).attr('data-theme', data[0]);
1302
					}
1303
				}
1304
1305
				themeTrigger(SaveSettingsStep.TrueResult);
1306
			}
1307
1308
		}).then(clearTimer, clearTimer);
1309
	}
1310
}
1311
1312
/**
1313
 * @returns {function}
1314
 */
1315
export function computedPagenatorHelper(koCurrentPage, koPageCount)
0 ignored issues
show
Unused Code introduced by
The parameter koPageCount is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter koCurrentPage is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
1316
{
1317
	return () => {
1318
1319
		const
1320
			currentPage = koCurrentPage(),
1321
			pageCount = koPageCount(),
1322
			result = [],
1323
			fAdd = (index, push = true, customName = '') => {
1324
1325
				const data = {
1326
					current: index === currentPage,
1327
					name: '' === customName ? index.toString() : customName.toString(),
1328
					custom: '' !== customName,
1329
					title: '' === customName ? '' : index.toString(),
1330
					value: index.toString()
1331
				};
1332
1333
				if (push)
1334
				{
1335
					result.push(data);
1336
				}
1337
				else
1338
				{
1339
					result.unshift(data);
1340
				}
1341
			};
1342
1343
		let
1344
			prev = 0,
1345
			next = 0,
1346
			limit = 2;
1347
1348
		if (1 < pageCount || (0 < pageCount && pageCount < currentPage))
1349
		{
1350
			if (pageCount < currentPage)
1351
			{
1352
				fAdd(pageCount);
1353
				prev = pageCount;
1354
				next = pageCount;
1355
			}
1356
			else
1357
			{
1358
				if (3 >= currentPage || pageCount - 2 <= currentPage)
1359
				{
1360
					limit += 2;
1361
				}
1362
1363
				fAdd(currentPage);
1364
				prev = currentPage;
1365
				next = currentPage;
1366
			}
1367
1368
			while (0 < limit) {
1369
1370
				prev -= 1;
1371
				next += 1;
1372
1373
				if (0 < prev)
1374
				{
1375
					fAdd(prev, false);
1376
					limit -= 1;
1377
				}
1378
1379
				if (pageCount >= next)
1380
				{
1381
					fAdd(next, true);
1382
					limit -= 1;
1383
				}
1384
				else if (0 >= prev)
1385
				{
1386
					break;
1387
				}
1388
			}
1389
1390
			if (3 === prev)
1391
			{
1392
				fAdd(2, false);
1393
			}
1394
			else if (3 < prev)
1395
			{
1396
				fAdd(Math.round((prev - 1) / 2), false, '...');
1397
			}
1398
1399
			if (pageCount - 2 === next)
1400
			{
1401
				fAdd(pageCount - 1, true);
1402
			}
1403
			else if (pageCount - 2 > next)
1404
			{
1405
				fAdd(Math.round((pageCount + next) / 2), true, '...');
1406
			}
1407
1408
			// first and last
1409
			if (1 < prev)
1410
			{
1411
				fAdd(1, false);
1412
			}
1413
1414
			if (pageCount > next)
1415
			{
1416
				fAdd(pageCount, true);
1417
			}
1418
		}
1419
1420
		return result;
1421
	};
1422
}
1423
1424
/**
1425
 * @param {string} fileName
1426
 * @returns {string}
1427
 */
1428
export function getFileExtension(fileName)
0 ignored issues
show
Unused Code introduced by
The parameter fileName is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
1429
{
1430
	fileName = trim(fileName).toLowerCase();
0 ignored issues
show
Bug introduced by
The variable fileName seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.fileName.
Loading history...
1431
1432
	const result = fileName.split('.').pop();
0 ignored issues
show
Bug introduced by
The variable result seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.result.
Loading history...
1433
	return result === fileName ? '' : result;
1434
}
1435
1436
/**
1437
 * @param {string} fileName
1438
 * @returns {string}
1439
 */
1440
export function mimeContentType(fileName)
0 ignored issues
show
Unused Code introduced by
The parameter fileName is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
1441
{
1442
	let
1443
		ext = '',
0 ignored issues
show
Bug introduced by
The variable ext seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.ext.
Loading history...
1444
		result = 'application/octet-stream';
0 ignored issues
show
Bug introduced by
The variable result seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.result.
Loading history...
1445
1446
	fileName = trim(fileName).toLowerCase();
0 ignored issues
show
Bug introduced by
The variable fileName seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.fileName.
Loading history...
1447
1448
	if ('winmail.dat' === fileName)
1449
	{
1450
		return 'application/ms-tnef';
1451
	}
1452
1453
	ext = getFileExtension(fileName);
1454
	if (ext && 0 < ext.length && !isUnd(Mime[ext]))
0 ignored issues
show
Best Practice introduced by
If you intend to check if the variable ext is declared in the current environment, consider using typeof ext === "undefined" instead. This is safe if the variable is not actually declared.
Loading history...
1455
	{
1456
		result = Mime[ext];
1457
	}
1458
1459
	return result;
1460
}
1461
1462
/**
1463
 * @param {string} url
1464
 * @param {number} value
1465
 * @param {Function} fCallback
1466
 */
1467
export function resizeAndCrop(url, value, fCallback)
0 ignored issues
show
Unused Code introduced by
The parameter url is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter value is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter fCallback is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
1468
{
1469
	const img = new window.Image();
0 ignored issues
show
Bug introduced by
The variable img seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.img.
Loading history...
1470
	img.onload = function() {
1471
1472
		let
1473
			diff = [0, 0];
0 ignored issues
show
Unused Code introduced by
The assignment to variable diff seems to be never used. Consider removing it.
Loading history...
1474
1475
		const
1476
			canvas = window.document.createElement('canvas'),
1477
			ctx = canvas.getContext('2d');
1478
1479
		canvas.width = value;
1480
		canvas.height = value;
1481
1482
		if (this.width > this.height)
1483
		{
1484
			diff = [this.width - this.height, 0];
1485
		}
1486
		else
1487
		{
1488
			diff = [0, this.height - this.width];
1489
		}
1490
1491
		ctx.fillStyle = '#fff';
1492
		ctx.fillRect(0, 0, value, value);
1493
		ctx.drawImage(this, diff[0] / 2, diff[1] / 2, this.width - diff[0], this.height - diff[1], 0, 0, value, value);
1494
1495
		fCallback(canvas.toDataURL('image/jpeg'));
1496
	};
1497
1498
	img.src = url;
1499
}
1500
1501
/**
1502
 * @param {string} mailToUrl
1503
 * @param {Function} PopupComposeVoreModel
1504
 * @returns {boolean}
1505
 */
1506
export function mailToHelper(mailToUrl, PopupComposeVoreModel)
0 ignored issues
show
Unused Code introduced by
The parameter PopupComposeVoreModel is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter mailToUrl is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
1507
{
1508
	if (mailToUrl && 'mailto:' === mailToUrl.toString().substr(0, 7).toLowerCase())
0 ignored issues
show
Best Practice introduced by
If you intend to check if the variable mailToUrl is declared in the current environment, consider using typeof mailToUrl === "undefined" instead. This is safe if the variable is not actually declared.
Loading history...
1509
	{
1510
		if (!PopupComposeVoreModel)
0 ignored issues
show
Best Practice introduced by
If you intend to check if the variable PopupComposeVoreModel is declared in the current environment, consider using typeof PopupComposeVoreModel === "undefined" instead. This is safe if the variable is not actually declared.
Loading history...
1511
		{
1512
			return true;
1513
		}
1514
1515
		mailToUrl = mailToUrl.toString().substr(7);
0 ignored issues
show
Bug introduced by
The variable mailToUrl seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.mailToUrl.
Loading history...
1516
1517
		let
1518
			to = [],
0 ignored issues
show
Bug introduced by
The variable to seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.to.
Loading history...
1519
			cc = null,
0 ignored issues
show
Bug introduced by
The variable cc seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.cc.
Loading history...
1520
			bcc = null,
0 ignored issues
show
Bug introduced by
The variable bcc seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.bcc.
Loading history...
1521
			params = {};
0 ignored issues
show
Bug introduced by
The variable params seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.params.
Loading history...
1522
1523
		const
1524
			email = mailToUrl.replace(/\?.+$/, ''),
0 ignored issues
show
Bug introduced by
The variable email seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.email.
Loading history...
1525
			query = mailToUrl.replace(/^[^\?]*\?/, ''),
0 ignored issues
show
Bug introduced by
The variable query seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.query.
Loading history...
1526
			EmailModel = require('Model/Email').default,
0 ignored issues
show
Bug introduced by
The variable EmailModel seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.EmailModel.
Loading history...
1527
			emailObj = new EmailModel(),
0 ignored issues
show
Bug introduced by
The variable emailObj seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.emailObj.
Loading history...
1528
			fParseEmailLine = (line) => (line ? _.compact(_.map(decodeURIComponent(line).split(/[,]/), (item) => {
0 ignored issues
show
Bug introduced by
The variable fParseEmailLine seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.fParseEmailLine.
Loading history...
Bug introduced by
The variable line seems to be never initialized.
Loading history...
introduced by
This code is unreachable and can thus be removed without consequences.
Loading history...
1529
				emailObj.clear();
1530
				emailObj.mailsoParse(item);
1531
				return '' !== emailObj.email ? emailObj : null;
1532
			})) : null);
1533
1534
		to = fParseEmailLine(email);
0 ignored issues
show
Bug introduced by
The variable to seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.to.
Loading history...
1535
		params = simpleQueryParser(query);
0 ignored issues
show
Bug introduced by
The variable params seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.params.
Loading history...
1536
1537
		if (!isUnd(params.cc))
1538
		{
1539
			cc = fParseEmailLine(decodeURIComponent(params.cc));
0 ignored issues
show
Bug introduced by
The variable cc seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.cc.
Loading history...
1540
		}
1541
1542
		if (!isUnd(params.bcc))
1543
		{
1544
			bcc = fParseEmailLine(decodeURIComponent(params.bcc));
0 ignored issues
show
Bug introduced by
The variable bcc seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.bcc.
Loading history...
1545
		}
1546
1547
		require('Knoin/Knoin').showScreenPopup(PopupComposeVoreModel, [
1548
			ComposeType.Empty, null, to, cc, bcc,
1549
			isUnd(params.subject) ? null : pString(decodeURIComponent(params.subject)),
1550
			isUnd(params.body) ? null : plainToHtml(pString(decodeURIComponent(params.body)))
1551
		]);
1552
1553
		return true;
1554
	}
1555
1556
	return false;
1557
}
1558
1559
/**
1560
 * @param {Function} fn
1561
 * @returns {void}
1562
 */
1563
export function domReady(fn)
0 ignored issues
show
Unused Code introduced by
The parameter fn is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
1564
{
1565
	$(() => fn());
1566
//
1567
//	if ('loading' !== window.document.readyState)
1568
//	{
1569
//		fn();
1570
//	}
1571
//	else
1572
//	{
1573
//		window.document.addEventListener('DOMContentLoaded', fn);
1574
//	}
1575
}
1576
1577
export const windowResize = _.debounce((timeout) => {
0 ignored issues
show
Unused Code introduced by
The constant windowResize seems to be never used. Consider removing it.
Loading history...
1578
	if (isUnd(timeout) || isNull(timeout))
1579
	{
1580
		$win.resize();
1581
	}
1582
	else
1583
	{
1584
		window.setTimeout(() => {
1585
			$win.resize();
1586
		}, timeout);
1587
	}
1588
}, 50);
1589
1590
/**
1591
 * @returns {void}
1592
 */
1593
export function windowResizeCallback()
1594
{
1595
	windowResize();
1596
}
1597
1598
let substr = window.String.substr;
1599
if ('b' !== 'ab'.substr(-1))
1600
{
1601
	substr = (str, start, length) => {
1602
		start = 0 > start ? str.length + start : start;
1603
		return str.substr(start, length);
1604
	};
1605
1606
	window.String.substr = substr;
1607
}
1608